import { displayTyepMap } from '@/config/dict'
import { parseTime } from '@/utils'
import { CustomStatus } from '@/components'

export const searchFormItem = [
  {
    type: 'input',
    key: 'keyword',
    label: '上报人'
  },
  {
    type: 'select',
    key: 'display',
    label: '是否展示',
    options: displayTyepMap
  },
  {
    type: 'date',
    subKey: ['beginDate', 'endDate'],
    key: 'beginDate',
    label: '上报时间',
    otherAttrs: {
      type: 'daterange',
      style: { width: '300px' }
    }
  }
]

export const tableColumn = (handleDetail, handleUpdateStatus, handleDelete) => {
  return [
    {
      key: 'content',
      label: '内容',
      minWidth: 240
    },
    {
      key: 'imageList',
      label: '照片',
      width: 200,
      render: (h, scope) => {
        const imgList = scope.row.imageList
        if (imgList && imgList.length) {
          const urlList = imgList.map(item => item.fileUrl)
          return urlList.map(url => {
            return (
              <el-image
                style={{ width: '30px', height: '30px', marginRight: '6px' }}
                src={url}
                preview-src-list={urlList}>
              </el-image>
            )
          })
        } else {
          return '-'
        }
      }
    },
    {
      key: 'userName',
      label: '上报人姓名',
      width: 100
    },
    {
      key: 'userLogo',
      label: '上报人头像',
      width: 100,
      render: (h, scope) => <el-avatar icon='el-icon-user-solid' size='small' src={scope.row.userLogo}></el-avatar>
    },
    // {
    //   key: '',
    //   label: '照片缩略图',
    //   minWidth: 200,
    //   render: (h, scope) =>
    // },
    {
      key: 'display',
      label: '是否展示',
      width: 100,
      render: (h, scope) => <CustomStatus list={displayTyepMap} value={scope.row.display} />
    },
    {
      key: 'createTime',
      label: '上报时间',
      width: 200,
      render: (h, scope) => parseTime(scope.row.createTime)
    },
    {
      type: 'button',
      label: '操作',
      list: [
        {
          name: '打赏记录',
          authKey: 'd_2_1',
          click: (e) => handleDetail(e, 'first')
        },
        {
          name: '点赞/评论记录',
          authKey: 'd_2_1',
          click: (e) => handleDetail(e, 'second')
        },
        {
          name: (scope) => scope.row.display ? '不展示' : '展示　',
          authKey: 'd_2_2',
          click: (id) => handleUpdateStatus(id)
        },
        {
          name: '删除',
          authKey: 'd_2_3',
          confirm: '确定删除吗?',
          click: handleDelete
        }
      ]
    }
  ]
}
